<template>
	<view class="shopping">
		<Header></Header>
		<view class="content">
			<view class="title">告 示</view>
			<scroll-view scroll-x class="scroll_box">
				<view class="item" :class="active==item.key?'active':''" :key="item.id" v-for="(item,index) in scroll"
					@click="change(item.key)">
					{{item.title}}
				</view>
			</scroll-view>
			<scroll-view scroll-y class="scroll_view">
				<view class="item" v-for="item in list" @click="router(`/pages/other/deta?id=${item.id}`)">
					<view class="item_view">
						<view class="name">{{item.title}}</view>
						<view class="time">{{item.created_at}}</view>
					</view>
					<image :src="item.img"></image>
				</view>
			</scroll-view>
		</view>
		<Footer active="2"></Footer>
	</view>
</template>

<script>
	import {
		newLists
	} from "@/request/api.js"
	import Header from "@/components/tabbar/Header.vue";
	import Footer from "@/components/tabbar/Footer.vue";
	export default {
		components: {
			Header,
			Footer
		},
		data() {
			return {
				active: 0,
				scroll: [],
				list: []
			}
		},
		async onLoad() {
			let res = await newLists();
			let scroll = this.scroll = res.class;

			// let keys = Object.keys(scroll);
			this.active = scroll.length ? scroll[0].key : "";

			let list = res.list;
			this.last_page = list.last_page;
			this.list = this.page == 1 ? list.list : [...this.list, ...list.list];
			this.loadmore_status = this.last_page == this.page ? 'nomore' : 'loadmore';
		},
		onHide() {
			this.list = [];
			this.page = 1;
		},
		methods: {
			async getList() {
				let res = await newLists({
					class_id: this.active,
					page: this.page,
					limit: this.limit
				});
				let list = res.list;
				this.last_page = list.last_page;
				this.list = this.page == 1 ? list.list : [...this.list, ...list.list];
				this.loadmore_status = this.last_page == this.page ? 'nomore' : 'loadmore';
			},
			loadmore() {
				if (this.page < this.last_page) {
					this.page++;
					this.getList();
				}
			},
			change(event) {
				this.active = event;
				this.list = [];
				this.page = 1;
				this.getList();
			}
		}
	}
</script>
<style scoped lang="scss">
	.shopping {
		background: #29170D;
		height: 100vh;
		padding-top: 80rpx;
		box-sizing: border-box;
		overflow: hidden;

		.content {
			height: calc(100vh - #{$tabbarFooterHeihgt} - 80rpx);
			padding: 104rpx 82rpx 0;
			box-sizing: border-box;
			background: url(#{$baseImageUrl}/bg/bg10.png) no-repeat;
			background-size: 100% 100%;
			position: relative;

			.title {
				width: 262rpx;
				height: 80rpx;
				line-height: 90rpx;
				text-align: center;
				color: #FFFFFF;
				font-size: 30rpx;
				font-weight: 400;
				font-family: LiSu;
				background: url(#{$baseImageUrl}/shopping/title.png) no-repeat;
				background-size: 100% 100%;
				position: absolute;
				left: 50%;
				top: 0;
				z-index: 2;
				transform: translateX(-50%);
			}

			.scroll_box {
				height: 80rpx;
				padding-bottom: 20rpx;
				box-sizing: border-box;
				white-space: nowrap;

				.item {
					display: inline-block;
					width: 150rpx;
					height: 60rpx;
					line-height: 60rpx;
					text-align: center;
					color: #494338;
					font-size: 30rpx;
					font-weight: 400;
					font-family: LiSu;

					&.active {
						color: #FFFFFF;
						background: url(#{$baseImageUrl}/common/active.png) no-repeat;
						background-size: 100% 100%;
					}

					&:last-child {
						margin: 0;
					}
				}
			}

			.scroll_view {
				height: calc(100% - 80rpx);

				.item {
					width: 100%;
					height: 238rpx;
					margin-bottom: 20rpx;
					padding: 25rpx;
					box-sizing: border-box;
					background: url(#{$baseImageUrl}/bg/586_238.png) no-repeat;
					background-size: 100% 100%;
					display: flex;

					.item_view {
						flex: 1;
						padding-top: 18rpx;
						padding-right: 15rpx;
						box-sizing: border-box;
						overflow: hidden;

						.name {
							color: #494338;
							font-size: 50rpx;
							font-weight: 400;
							font-family: LiSu;
							margin-bottom: 28rpx;
						}

						.time {
							color: #494338;
							font-size: 28rpx;
							font-weight: 400;
							font-family: SimSun;
						}
					}

					image {
						width: 180rpx;
						height: 180rpx;
					}
				}
			}
		}
	}
</style>